<?php 

//phpinfo();
include "config.php";

/*$act = $_REQUEST['act'];
if($act == 'add'){
	if($_FILES['file']['name'] == ''){
		echo '请重新上传';
		header('Location: ./');exit;
	}
	
	require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel.php';
	require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel2007.php';
	require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel5.php';
	require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/IOFactory.php';
	
	
	date_default_timezone_set('Europe/London'); //设置时间
	
	$name = $_FILES['file']['name'];
	$inputFileName = $_FILES['file']['tmp_name'];
	
	//判断一下，文件是2007还是旧版的excel
	if(strstr($name,".")==".xls")
	{
		$inputFileType = 'Excel5';
	}
	else if(strstr($name,".")==".xlsx")
	{
		$inputFileType = 'Excel2007';
	}
	else
	{
		echo $name;
	
		echo "请检查文件格式";
	}
	
	$objReader = PHPExcel_IOFactory::createReader($inputFileType);
	$objPHPExcel = $objReader->load($inputFileName);
	
	$objWorksheet = $objPHPExcel->getActiveSheet();//取得总行数
	$highestRow = $objWorksheet->getHighestRow();//取得总列数
	
	//echo 'highestRow='.$highestRow;
	//echo "<br>";
	$highestColumn = $objWorksheet->getHighestColumn();
	$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
	//echo 'highestColumnIndex='.$highestColumnIndex;
	//echo "<br />";
	
	
	
	$headtitle=array();
	$result=array();
	
	for ($row = 0;$row <= $highestRow;$row++)
	{
		$strs=array();
		//注意highestColumnIndex的列数索引从0开始
		for ($col = 0;$col < $highestColumnIndex;$col++)
		{
			$strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
	
			$result[$row][$col]=$strs[$col];
		}
	
	
	}
	
	foreach($result as $key=>$value){
		if($key > 1 && $value[4] == '市局机关'){
			$sqlstr="SELECT nid FROM `athlon_department` where name = '$value[1]' ";
			
			$department_info = mysqli_fetch_assoc(do_query($sqlstr));
			
			$department_id = $department_info['nid'];
			
			if($value[2] != ''){
				$sqlstr="insert into  `athlon_user` (`name`,`mid`,`department`,`password`,`phone`) value('$value[2]','$value[0]','$department_id','".md5('123')."','$value[3]')  ";
				do_query("$sqlstr");
			}
		}
	}
	echo "<script>alert('更新成功')</script>";
	
	exit;
}*/

/*$end_data = strtotime("2019-06-30");
$start_data = strtotime("2018-05-25");

$days = ($end_data-$start_data)/(24*3600);

for($i=1;$i<=$days;$i++){
	$start_day = date('Y-m-d',$start_data+($i*24*3600)); 
	
	$sqlstr="SELECT COUNT(*) FROM `menu` where applydate = '$start_day' and meal = 1 ";
	$query = do_query("$sqlstr");
	$sum = mysqli_fetch_array($query)[0];
	
	if($sum == 0){
		
		$sqlstr="insert into  `menu` (`name`,`price`,`week`,`at`,`month`,`status`,`applydate`,`meal`) value('早餐','5','','1','','发布','$start_day',1)  ";
		 do_query("$sqlstr");
	}
	
	$sqlstr="SELECT COUNT(*) FROM `menu` where applydate = '$start_day' and meal = 2";
	$query = do_query("$sqlstr");
	$sum = mysqli_fetch_array($query)[0];
	
	if($sum == 0){
		
		$sqlstr="insert into  `menu` (`name`,`price`,`week`,`at`,`month`,`status`,`applydate`,`meal`) value('午餐','10','','2','','发布','$start_day',2)  ";
		 do_query("$sqlstr");
	}
}*/


//批量删除周六日菜单

/*$delete_arrray = array(0,6);

$term = select_lines_all_items('menu',"product_id","","");
foreach($term as $k => $val ){
    $date =strtotime($val['applydate']);
	
	$new_date = date("w",$date);
	
	if(in_array($new_date, $delete_arrray)){
		$sql = 'DELETE FROM `menu` WHERE at = 1 and product_id ='.$val['product_id'];
		
		do_query($sql);
	}
	
}*/

$sqlstr1="select name,mid from athlon_user ";

$result1 = do_query($sqlstr1);

while ($row1 = mysqli_fetch_assoc($result1)) {
    $user_info[$row1['mid']]          = $row1;
}



$sqlstr2="select * from account_log group by user_id  ";

$result2 = do_query($sqlstr2);

while ($row2 = mysqli_fetch_assoc($result2)) {
  
  	$sql = 'update account_log set name ="'.$user_info[$row2['user_id']]['name'].'"  where name="" and user_id ="'.$row2['user_id'].'"';
	do_query($sql);
  
}


?>

<!--<div>
<form action="update.php?act=add" enctype="multipart/form-data" method="post" >
<input type="file"  name="file" id="file" />
<input type="submit" value="提交" />
</form>
</div>-->